package gui.newComponent;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.*;
import javax.swing.*;
import java.awt.*;

public class FWButton extends JPanel{

    JButton button = new JButton();

    public void addActionListener(ActionListener l){
        button.addActionListener(l);
    }

    public void setDisabled(){
        button.setEnabled(false);
    }

    public void setEnabled(){
        button.setEnabled(true);
    }

    public void setIcon(String path) {
        button.setIcon(new ImageIcon(path));
        button.setIconTextGap(10);
    }

    public FWButton(String name, boolean flat){
        button.setText(name);
        button.setContentAreaFilled(!flat);
        button.addKeyListener(new KeyListener() {
            public void keyTyped(KeyEvent e) {}
            public void keyPressed(KeyEvent e) {}
            public void keyReleased(KeyEvent e) {
                int i = e.getKeyCode();
                if (i == KeyEvent.VK_ENTER){
                    button.doClick();
                }
            }
        });
        this.setLayout(new FlowLayout(FlowLayout.LEFT));
        this.add(button);
    }

}
